<template>
	<!-- accountdis账户与折扣设置 -->
	<view class="wp">
		<uni-forms ref="form" label-width="150px" label-position="top" :modelValue="dataInfo">
			<uni-forms-item label="让利设置" required name="discount">
				<uni-data-select @change="changeButie" v-model="dataInfo.discount" :localdata="rangli"></uni-data-select>
			</uni-forms-item>
			<view class="w_tip" style="margin-top: -20rpx;">
				<view>消费100元，用户最高补贴<text class="bold">{{dataInfo.discount*5}}</text>%
				</view>
				<view>商家到账<text class="redBold">{{number2}}</text>元(提现0手续费)</view>
				<view>商家最高补贴{{dataInfo.discount*5}}元</view>
			</view>
			<!-- <uni-forms-item label="补贴设置" required name="feerate">
				<view class="flex_between">
					<view>商家：{{dataInfo.feerate}}%</view>
					<view>消费者：{{userButie}}%</view>
				</view>
				<slider :max="maxButie" :value="dataInfo.feerate" @change="sliderChange" activeColor="#FF0000" backgroundColor="#D8BFD8" block-color="#9400D3" block-size="28" show-value="true"/>
			</uni-forms-item> -->
		</uni-forms>
		<view class="a_tip">
			<view class="tip">收款金额在多米街钱包余额中查看，可随时提现。</view>
			<button size="mini" @click="$navTo('/pages/userservice/withdrawal')">去查看 ></button>
		</view>
		<view class="a_tip" style="margin-bottom: 20rpx;">
			<view>实时到账功能，正在内测中.....</view>
		</view>
		<!-- <view class="" style="text-align: center;">
			<button class="sub" :disabled="isstop" @click="submit"></button>
		</view> -->
		<view class="totalBtn" @click="submit">提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uid: '',
				dataInfo: {
					aliaccount: "",
					aliname: "",
					discount: "",
					salediscount:'',
					// feerate: 0,
				},
				userButie: 0,
				// maxButie: 0,
				Number: 0,
				shijiNumber: 0,
				isstop: false,
				rangli: [
					{value:3,text:'3%'},
					{value:4,text:'4%'},
					{value:5,text:'5%'},
					{value:6,text:'6%'},
					{value:7,text:'7%'},
					{value:8,text:'8%'},
					{value:9,text:'9%'},
					{value:10,text:'10%'},
					{value:11,text:'11%'},
					{value:12,text:'12%'},
					{value:13,text:'13%'},
					{value:14,text:'14%'},
					{value:15,text:'15%'},
					{value:16,text:'16%'},
					{value:17,text:'17%'},
					{value:18,text:'18%'},
					{value:19,text:'19%'},
					{value:20,text:'20%'},
				],
				rules: {
					// aliname: {
					// 	rules: [{
					// 		required: true,
					// 		errorMessage: '姓名不能为空'
					// 	}]
					// },
					// aliaccount: {
					// 	rules: [{
					// 		required: true,
					// 		errorMessage: '支付宝账号不能为空'
					// 	}]
					// },
					discount: {
						rules: [{
							required: true,
							errorMessage: '请正确填写折扣'
						}, {
							validateFunction: function(rule, value, data, callback) {
								let reg = /^\d+\.?\d?$/;
								if (!reg.test(value) || value > 99) callback('请正确填写折扣');
							}
						}]
					},
					salediscount: {
						rules: [{
							required: true,
							errorMessage: '请正确填写推广费'
						}, {
							validateFunction: function(rule, value, data, callback) {
								let reg = /^\d+\.?\d?$/;
								if (!reg.test(value) || value > 30) callback('请正确填写推广费');
							}
						}]
					},
				},
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		onLoad(options) {
			this.uid = options.uid;
			this.getInfo();
		},
		computed: {
		    number1: function() {
		      return (10*this.Number).toFixed(2);
		    },
			number2: function() {
			  // return (100-(10*this.Number)).toFixed(2);
			  return (100 - (100 * (this.dataInfo.discount / 100))).toFixed(2);
			},
			maxButie: {
				
				get() {
				    return this.dataInfo.discount * 6;
				},
				set(val) {
				    return val
				}
			}
		},
		methods: {
			sliderChange(e) {
				this.dataInfo.feerate = e.detail.value;
				this.userButie = this.maxButie - e.detail.value;
			},
			changeButie(e){
				 // this.dataInfo.feerate = e;
				 this.userButie = e*5;
			},
			getInfo() {
				this.$axios('info/getPaydiscount', 'POST', 'supplier', {
					uid: this.uid
				}).then(res => {
					if (res.data.code == 200) {
						this.dataInfo = res.data.data;
						this.Number = ((res.data.data.discount/10) + (res.data.data.salediscount/10)).toFixed(2);
						this.maxButie = this.dataInfo.discount * 6;
						// this.userButie = this.dataInfo.discount * 6 - this.dataInfo.feerate;
					}
				})
			},
			submit() {
				var that = this;
				if(!that.dataInfo.discount){
					return that.$api.msg('请选择让利');
				}else{
					that.submit2();
				}
			},
			submit2(){
				this.isstop = true;
				this.$axios('info/savePaydiscount', 'POST', 'supplier', {
					...this.dataInfo,
					uid: this.uid
				}).then(res => {
					this.isstop = false;
					if (res.data.code == 200) {
						this.$api.msg('设置成功！');
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.wp {
		padding: 20upx;
	}
	.a_blue{
		color: #2979ff;
		margin: 30rpx 0 50rpx;
		line-height: 1.8;
	}
	.w_tip{
		margin-bottom: 30rpx;
		line-height: 1.6;
		.tit{
			color:#606266;;
		}
		.s_tit{
			font-size: 24rpx;
			color: #999;
		}
	}
	.redBold{
		font-weight: bold;
		color: red;
	}
	.bold{
		font-weight: bold;
	}
	.a_tip{
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: #999;
		font-size: 24rpx;
		.tip{
			flex: 1;
		}
		button{
			margin: 0;
			background: $bg-color;
			color: #fff;
			font-size: 24rpx;
			width: 134rpx;
			padding: 0;
			&::after{
				border: none;
			}
		}
	}
	.message {
		color: #4399fc;
		font-size: 24upx;
	}

	.sub {
		background: #18bc37;
		color: #fff;
		font-size: 28upx;
		line-height: 80upx;
		width: 90%;
	}
</style>